<template>
  <div class="content_box">
    <div class="main-box">
      <p class="main-title">完善办案日期</p>
      <p class="main-text">注：取保时间一旦修改不可修改，日期请与文书一直后续可案件延期申请。</p>
      <el-form :model="form" :rules="rules" ref="updateForms">
        <el-form-item
          prop="start_date"
          label="取保开始日期"
          label-width="120px"
        >
          <el-date-picker
            style="width:90%"
            size="large"
            v-model="form.start_date"
            type="datetime"
            placeholder="请选择取保开始日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item prop="end_date" label="取保结束日期" label-width="120px">
          <el-date-picker
            style="width:90%"
            size="large"
            v-model="form.end_date"
            type="datetime"
            placeholder="请选择取保结束日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button
          :loading="loading"
          :disabled="loading"
          type="primary"
          @click="submit"
        >
          提交
        </el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref,onMounted,defineProps, defineEmits } from "vue";
import { ElNotification } from "element-plus";
import { updateBailDate } from "@/api/bond/pay";

const props = defineProps({
  id: {
    type: Number,
  },
});

let form = ref({
  bail_id: props.id,
  start_date: "",
  end_date: "",
});

const emit = defineEmits(['closeDrawer']);

onMounted(() => {
});

/*=====提交=====*/
const updateForms = ref();
let loading = ref(false);
const rules = reactive({
  start_date: [
    { required: true, message: "请选择取保开始日期", trigger: "change" },
  ],
  end_date: [
    { required: true, message: "请选择取保结束日期", trigger: "change" },
  ],
});

const submit = async () => {
  await updateForms.value.validate();
  console.log(form.value)
  loading.value = true;

  await updateBailDate(form.value).then((res) => {
    if (res.code == 1) {
      ElNotification({ message: res.msg, type: "success" });
      close()
    } else {
      loading.value = false;
      ElNotification.error(res.msg);
    }
  });
};

// 关闭
const close=()=>{
  form.value.start_date = ''
  form.value.end_date = ''
  loading.value = false
  emit("closeDrawer");
}

</script>
<style scoped lang="scss">
.dialog-footer {
  margin-top:50px;
  text-align: center;
}
.main-box{
  min-height: auto;
}
.main-text{
  margin:20px 0 47px 0;
  font-size: 14px;
  color: #323C4F;
}
</style>
  